﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>


<base href="<%=basePath%>">
<!-- jsp文件头和头部 -->
<%@ include file="../../system/admin/top.jsp"%>
<script type="text/javascript">
$(function(){
	$(top.hangge());
	// 初始化公司
	//showTree("company", {}, '${pd.company_id}');
	
	

})
</script>
</head>
<body>

	<div class="container-fluid" id="main-container">


		<div id="page-content" class="clearfix">

			<div class="row-fluid">


				<div class="row-fluid">

					<!-- 检索  -->
					<form action="uuser/listUsers.do" method="post" name="userForm"
						id="userForm">
						<table>
							<tr>
								<td><span class="input-icon"> <input
										autocomplete="off" id="nav-search-input" type="text"
										name="USERNAME" value="${pd.USERNAME }" placeholder="这里输入关键词" />
										<i id="nav-search-icon" class="icon-search"></i>
								</span></td>
								<td><input class="span10 date-picker" name="lastLoginStart"
									id="lastLoginStart" value="${pd.lastLoginStart}" type="text"
									data-date-format="yyyy-mm-dd" readonly="readonly"
									style="width: 88px;" placeholder="开始日期" title="最近登录开始" /></td>
								<td><input class="span10 date-picker" name="lastLoginEnd"
									id="lastLoginEnd" value="${pd.lastLoginEnd}" type="text"
									data-date-format="yyyy-mm-dd" readonly="readonly"
									style="width: 88px;" placeholder="结束日期" title="最近登录结束" /></td>
									<td style="vertical-align: top;"><select
									class="chzn-select" name="type" id="type" data-placeholder="用户类型"
									style="vertical-align: top; width: 100px;">
										<option value="" selected="selected">全部</option>
										<option value="0"
											<c:if test="${pd.type == '0' }">selected</c:if>>普通用户</option>
										<option value="1"
											<c:if test="${pd.type == '1' }">selected</c:if>>管理用户</option>
								</select></td>
								<c:if test="${QX.cha == 1 }">
									<td style="vertical-align: top;"><button
											class="btn btn-mini btn-light" onclick="search();" title="检索">
											<i id="nav-search-icon" class="icon-search"></i>
										</button></td>
									<td style="vertical-align: top;"><a
										class="btn btn-mini btn-light"
										onclick="window.location.href='<%=basePath%>/uuser/listtabUsers.do';"
										title="切换模式"><i id="nav-search-icon" class="icon-exchange"></i></a></td>
									<td style="vertical-align: top;"><a
										class="btn btn-mini btn-light" onclick="toExcel();"
										title="导出到EXCEL"><i id="nav-search-icon"
											class="icon-download-alt"></i></a></td>
									<c:if test="${QX.edit == 1 }">
										<td style="vertical-align: top;"><a
											class="btn btn-mini btn-light" onclick="fromExcel();"
											title="从EXCEL导入"><i id="nav-search-icon"
												class="icon-cloud-upload"></i></a></td>
									</c:if>
								</c:if>
							</tr>
						</table>
						<!-- 检索  -->


						<table id="table_report"
							class="table table-striped table-bordered table-hover">

							<thead>
								<tr>
									<th class="center"><label><input type="checkbox"
											id="zcheckbox" /><span class="lbl"></span></label></th>
									<th>序号</th>
									<th>编号</th>
									<th>用户名</th>
									<th>姓名</th>
									<th>职位</th>
									<th><i class="icon-envelope"></i>邮箱</th>
									<th>公司</th>
									<th>部门</th>
									<th><i class="icon-time hidden-phone"></i>最近登录</th>
									<th>上次登录IP</th>
									<th>用户类型</th>
									<th class="center">操作</th>
								</tr>
							</thead>

							<tbody>

								<!-- 开始循环 -->
								<c:choose>
									<c:when test="${not empty userList}">
										<c:if test="${QX.cha == 1 }">
											<c:forEach items="${userList}" var="user" varStatus="vs">

												<tr>
													<td class='center' style="width: 30px;"><c:if
															test="${user.USERNAME != 'admin'}">
															<label><input type='checkbox' name='ids'
																value="${user.USER_ID }" id="${user.EMAIL }"
																alt="${user.PHONE }" /><span class="lbl"></span></label>
														</c:if> <c:if test="${user.USERNAME == 'admin'}">
															<label><input type='checkbox' disabled="disabled" /><span
																class="lbl"></span></label>
														</c:if></td>
													<td class='center' style="width: 30px;">${vs.index+1}</td>
													<td>${user.NUMBER }</td>
													<td><a>${user.USERNAME }</a></td>
													<td>${user.NAME }</td>
													<td>${user.ROLE_NAME }</td>
													<c:if test="${QX.FX_QX == 1 }">
														<td><a title="发送电子邮件"
															style="text-decoration: none; cursor: pointer;"
															onclick="sendEmail('${user.EMAIL }');">${user.EMAIL
																}&nbsp;<i class="icon-envelope"></i>
														</a></td>
													</c:if>
													<c:if test="${QX.FX_QX != 1 }">
														<td><a title="您无权发送电子邮件"
															style="text-decoration: none; cursor: pointer;">${user.EMAIL
																}&nbsp;<i class="icon-envelope"></i>
														</a></td>
													</c:if>
													<td>${user.companyname}</td>
													<td>${user.departname}</td>
													<td>${user.LAST_LOGIN}</td>
													<td>${user.IP}</td>
													<td><c:if test="${user.type == '0' }">
															<span class="label label-success arrowed">普通用户</span>
														</c:if> <c:if test="${user.type == '1' }">
															<span class="label label-important arrowed-in">管理用户</span>
														</c:if></td>
													<td style="width: 60px;">
														<div class='hidden-phone visible-desktop btn-group'>

															<c:if test="${QX.cha == 1 }">
																<a class='btn btn-mini btn-light' title="详细"
																	onclick="find('${user.USER_ID }');"><i
																	class='icon-tasks'></i></a>
															</c:if>
															<c:if test="${QX.edit == 1 }">
																<c:if test="${user.USERNAME != 'admin'}">
																	<a class='btn btn-mini btn-info' title="编辑"
																		onclick="editUser('${user.USER_ID }');"><i
																		class='icon-edit'></i></a>
																</c:if>
																<c:if test="${user.USERNAME == 'admin'}">
																	<a class='btn btn-mini btn-info' title="您不能编辑"><i
																		class='icon-edit'></i></a>
																</c:if>
															</c:if>
															<c:choose>
																<c:when test="${user.USERNAME=='admin'}">
																	<a class='btn btn-mini btn-danger' title="不能删除"><i
																		class='icon-trash'></i></a>
																</c:when>
																<c:otherwise>
																	<c:if test="${QX.del == 1 }">
																		<a class='btn btn-mini btn-danger' title="删除"
																			onclick="delUser('${user.USER_ID }','${user.USERNAME }');"><i
																			class='icon-trash'></i></a>
																	</c:if>
																</c:otherwise>
															</c:choose>
														</div>
													</td>
												</tr>

											</c:forEach>
										</c:if>

										<c:if test="${QX.cha == 0 }">
											<tr>
												<td colspan="10" class="center">您无权查看</td>
											</tr>
										</c:if>
									</c:when>
									<c:otherwise>
										<tr class="main_info">
											<td colspan="10" class="center">没有相关数据</td>
										</tr>
									</c:otherwise>
								</c:choose>


							</tbody>
						</table>

						<div class="page-header position-relative">
							<table style="width: 100%;">
								<tr>
									<td style="vertical-align: top;"><c:if
											test="${QX.add == 1 }">
											<a class="btn btn-small btn-success" onclick="add();">新增</a>
										</c:if> <c:if test="${QX.del == 1 }">
											<a title="批量删除" class="btn btn-small btn-danger"
												onclick="makeAll('确定要删除选中的数据吗?');"><i
												class='icon-trash'></i></a>
										</c:if></td>
									<td style="vertical-align: top;"><div class="pagination"
											style="float: right; padding-top: 0px; margin-top: 0px;">${page.pageStr}</div></td>
								</tr>
							</table>
						</div>
					</form>
				</div>




				<!-- PAGE CONTENT ENDS HERE -->
			</div>
			<!--/row-->

		</div>
		<!--/#page-content-->
	</div>
	<!--/.fluid-container#main-container-->

	<!-- 返回顶部  -->
	<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse"> <i
		class="icon-double-angle-up icon-only"></i>
	</a>

	<!-- 引入 -->
	<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
	<script src="static/js/bootstrap.min.js"></script>
	<script src="static/js/ace-elements.min.js"></script>
	<script src="static/js/ace.min.js"></script>

	<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script>
	<!-- 下拉框 -->
	<script type="text/javascript"
		src="static/js/bootstrap-datepicker.min.js"></script>
	<!-- 日期框 -->
	<script type="text/javascript" src="static/js/bootbox.min.js"></script>
	<!-- 确认窗口 -->
	<!-- 引入 -->


	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<!--提示框-->
	<script type="text/javascript">
		
		$(top.hangge());
		
		//检索
		function search(){
			top.jzts();
			$("#userForm").submit();
		}
		
		//新增
		function add(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增";
			 diag.URL = '<%=basePath%>uuser/goAddU.do';
			 diag.Width = 240;
			 diag.Height = 420;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 if('${page.currentPage}' == '0'){
						 top.jzts();
						 setTimeout("self.location=self.location",100);
					 }else{
						 nextPage(${page.currentPage});
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//修改
		function editUser(user_id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="资料";
			 diag.URL = '<%=basePath%>uuser/goEditU.do?USER_ID='+user_id;
			 diag.Width = 240;
			 diag.Height = 420;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					nextPage(${page.currentPage});
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//查看详细
		function find(user_id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="详细";
			 diag.URL = '<%=basePath%>uuser/goFindU.do?USER_ID='+user_id;
			 diag.Width = 250;
			 diag.Height = 480;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					nextPage(${page.currentPage});
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//删除
		function delUser(userId,msg){
			bootbox.confirm("确定要删除["+msg+"]吗?", function(result) {
				if(result) {
					top.jzts();
					var url = "<%=basePath%>uuser/deleteU.do?USER_ID="+userId+"&tm="+new Date().getTime();
					$.get(url,function(data){
						nextPage(${page.currentPage});
					});
				}
			});
		}
		
		//批量操作
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					var emstr = '';
					var phones = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++)
					{
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  	
						  	if(emstr=='') emstr += document.getElementsByName('ids')[i].id;
						  	else emstr += ';' + document.getElementsByName('ids')[i].id;
						  	
						  	if(phones=='') phones += document.getElementsByName('ids')[i].alt;
						  	else phones += ';' + document.getElementsByName('ids')[i].alt;
						  }
					}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						if(msg == '确定要删除选中的数据吗?'){
							top.jzts();
							$.ajax({
								type: "POST",
								url: '<%=basePath%>uuser/deleteAllU.do?tm='+new Date().getTime(),
						    	data: {USER_IDS:str},
								dataType:'json',
								//beforeSend: validateData,
								cache: false,
								success: function(data){
									 $.each(data.list, function(i, list){
											nextPage(${page.currentPage});
									 });
								}
							});
						}else if(msg == '确定要给选中的用户发送邮件吗?'){
							sendEmail(emstr);
						}else if(msg == '确定要给选中的用户发送短信吗?'){
							sendSms(phones);
						}
						
						
					}
				}
			});
		}
		
		</script>

	<script type="text/javascript">
		
		$(function() {
			
			//日期框
			$('.date-picker').datepicker();
			
			//下拉框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
			
		});
		
		//导出excel
		function toExcel(){
			var USERNAME = $("#nav-search-input").val();
			var lastLoginStart = $("#lastLoginStart").val();
			var lastLoginEnd = $("#lastLoginEnd").val();
			var ROLE_ID = $("#role_id").val();
			if(ROLE_ID==null||ROLE_ID=="null"){
				ROLE_ID="";
			}
			var type = $("#type").val();
			window.location.href='<%=basePath%>uuser/excel.do?USERNAME='+USERNAME+'&lastLoginStart='+lastLoginStart+'&lastLoginEnd='+lastLoginEnd+'&type='+type+'&ROLE_ID='+ROLE_ID;
		}
		
		//打开上传excel页面
		function fromExcel(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="EXCEL 导入到数据库";
			 diag.URL = '<%=basePath%>user/goUploadExcel.do';
			 diag.Width = 300;
			 diag.Height = 150;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 if('${page.currentPage}' == '0'){
						 top.jzts();
						 setTimeout("self.location.reload()",100);
					 }else{
						 nextPage(${page.currentPage});
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		
		</script>

</body>
</html>

